<?php

namespace app\admin\controller;

use app\admin\model\User;
use app\admin\model\WaterMining;
use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }
        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');
        $todayuserlogin = User::whereTime('logintime','today')->count();
        $todayusersignup = User::whereTime('jointime','today')->count();
        $totaluser = User::count();
        $sven_time = strtotime(date('Y-m-d',time())) - (3600 * 24 * 7);
        $sevendnu = \app\admin\model\User::whereTime('jointime','>=',$sven_time)->count();
        $sevendnu = round($sevendnu / $totaluser * 100, 1);
        $sevendau = User::whereTime('logintime','>=',$sven_time)->count();
        $sevendau = round($sevendau / $totaluser * 100, 1);
        $totalbuy = \app\admin\model\UserMiner::sum('number');
        $totaljihuo = \app\admin\model\UserMiner::sum('balance_number');
        $usdtamount = \app\admin\model\MiningRecharge::where('status',1)->where('mining_coin_str','usdt')->sum('money');
        $filamount = \app\admin\model\MiningRecharge::where('status',1)->where('mining_coin_str','fil')->sum('money');
        $usdtout = \app\admin\model\MiningWithdraw::where('status',1)->where('mining_coin_str','usdt')->sum('number');
        $filtout = \app\admin\model\MiningWithdraw::where('status',1)->where('mining_coin_str','fil')->sum('number');
        $fil_produce = WaterMining::whereIn('type',[MINING_WATER_MINING,MINING_WATER_LOCK_RELEASE])->sum('money');
        $market_produce = WaterMining::whereIn('type',MINING_WATER_DIRECT_PUSH,MINING_WATER_TEAM)->sum('money');
//        $todayprofit = NodeBalance::whereTime('create_time','today')->sum('profit');
//        $totalorderamount = NodeBalance::sum('profit');
//        $totalminer = Miner::count();
//        $machine = Miner::sum('machine');
        $this->view->assign([
            'totaluser'        => $totaluser,
            'totalviews'       => $totaluser,
            'total_buy'       => $totalbuy,
            'total_jihuo'       => $totaljihuo,
            'usdt_amount'       => $usdtamount,
            'fil_amount'       => $filamount,
            'usdt_out'       => $usdtout,
            'fil_out'       => $filtout,
            'fil_produce'       => $fil_produce ,
            'market_produce'       => $market_produce,
//            'todayprofit'       => $totalbuy,
//            'todayprofit'       => $totalbuy,
//            'todayprofit'       => $totalbuy,
//            'totalorderamount' => $totalorderamount,
            'todayuserlogin'   => $todayuserlogin,
            'todayusersignup'  => $todayusersignup,
            'todayorder'       => 2324,
//            'totalminer'       => $totalminer,
            'unsettleorder'    => 132,
            'sevendnu'         => '80%',
            'sevendau'         => '32%',
            'paylist'          => $paylist,
            'createlist'       => $createlist,
            'addonversion'       => $addonVersion,
            'uploadmode'       => $uploadmode
        ]);

        return $this->view->fetch();
    }

}
